package main

import (
	"bee-study/grpc/api"
	"context"
	"google.golang.org/grpc"
	"log"
)

func clientInterceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
	log.Printf("请求一下")
	err := invoker(ctx, method, req, reply, cc)
	return err
}

func main(){
	conn, err := grpc.Dial("127.0.0.1:50051", grpc.WithInsecure(), grpc.WithChainUnaryInterceptor(clientInterceptor))
	if err != nil {
		log.Fatal(err)
	}
	client := api.NewGreeterClient(conn)
	reply, err := client.SayHello(context.Background(), &api.HelloRequest{
		Name: "World",
	})
	if err != nil {
		log.Printf("请求 SayHello 失败， err: %s", err.Error())
		return
	}
	log.Print(reply)
	reply, err = client.SayHello(context.Background(), &api.HelloRequest{
		Name: "World",
	})
	if err != nil {
		log.Printf("请求 SayHello 失败， err: %s", err.Error())
		return
	}
	log.Print(reply)
	//for  {
	//	time.Sleep(1000 * time.Second)
	//}
}